{include file="common/header"}
<style>
   
    .table-responsive .cap-center th,.table-responsive table tbody td{
        text-align: center !important;
    }
    
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>商品列表</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row" style="margin-bottom: 15px;">
                            <div class="col-sm-12">
                                <div class="input-group col-sm-12">
                                    <form method="get" action="" class="clearfix pull-left" >
                                        <input type="hidden" name="p" value="1" title="分页次页搜索需要">
                                        <input type="text" name="keywords" value="<?php echo (isset($_GET['keywords']) && $_GET['keywords']) ? $_GET['keywords'] : ''; ?>" placeholder="商品名称" class="input-sm form-control pull-left col-sm-4" style="width:75%;" >
                                        <span class="input-group-btn pull-left " >
                                            <button type="submit" class="btn btn-sm btn-primary search-btn"> 搜索</button>
                                        </span>
                                    </form>
                                    <button type="button" onclick="javascript:window.location.href = '/Admin/Goods/list';" class="btn btn-danger btn-sm  reset-btn pull-left">刷新</button>
                                    <button type="button" onclick="javascript:window.location.href = '/Admin/Goods/add';" class="btn btn-primary btn-sm  reset-btn pull-left" style="">添加商品</button>
                                </div>
                            </div>
                        </div>
                        <?php if(isset($_GET['keywords']) && $_GET['keywords']): ?>
                        <div class="alert alert-success">
                            以下是搜索 “<b><?php echo $_GET['keywords']; ?></b>” 的结果：
                        </div>
                        <?php endif; ?>
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="full-height-scroll">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-hover">
                                            <tbody>
                                                <tr class="cap-center">
                                                    <td>序号</td>
                                                    <td>商品图片</td>
                                                    <td>商品名称</td>
                                                    <td>商品简介</td>
                                                    <td>添加时间</td>
                                                    <td>操作</td>
                                                </tr>
                                                <?php foreach($res as $k => $v): ?>
                                                <tr>
                                                    <td><?php echo ++ $page['firstRow']; ?></td>
                                                    <td>
                                                        <img style="width:50px;height: 50px;" src=<?php echo $v['goods_img']; ?>>
                                                    </td>
                                                    <td title="<?php echo $v['goods_name']; ?>"><?php echo mb_strlen($v['goods_name']) > 15 ? mb_substr($v['goods_name'],0,15).'....' : $v['goods_name']; ?></td>
                                                    <td title="<?php echo $v['describe']; ?>"><?php echo mb_strlen($v['describe']) > 25 ? mb_substr($v['describe'],0,25).'....' : $v['describe']; ?></td>
                                                    <td><?php echo $v['add_time']; ?></td>
                                                    <td>
                                                        <a href="/Admin/Goods/edit?goods_id=<?php echo $v['goods_id']; ?>"><span class="label label-success">编辑</span></a>
                                                        <a href="#"  onclick="javascript:deleteAction(<?php echo $v['goods_id'];?>);">
                                                            <span class="label label-danger">删除</span>
                                                        </a>
                                                    </td>
                                                </tr>
                                                <?php endforeach; ?>
                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <td colspan="12">
                                                        <div class="b-page">
                                                            <?php echo $page['page']; ?>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tfoot>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>

    var flog = false;

	function deleteAction(goods_id){

        swal({
            title: "确认要删除该商品吗？",
            text: "请谨慎操作",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确认删除",
            cancelButtonText: "考虑一下",
            closeOnConfirm: false,
            closeOnCancel: true
        },function(isConfirm){
            if (isConfirm) {
                if (flog) {
                    return;
                }
                flog = true;
                $.post('/Admin/Goods/delete',{goods_id:goods_id},function(d){
                    if(d.error)
                    {
                        swal(d.msg, "", "error");
                        return false;
                    }else{
                        swal(d.msg, "", "success");
                        setTimeout("window.location.reload();",1000);
                    }
                },'json');
            }
        });
	}

</script>
{include file="common/footer"}